Skip to content

feat(MediaMtx): refactor runtime camera management - #1387

Merged
ArgoZhang merged 1 commit into
masterfrom
chore-mediamtx
Dec 2, 2026
Merged

ArgoZhang merged 1 commit into
masterfrom
chore-mediamtx

Conversation

@ArgoZhang

@ArgoZhang ArgoZhang commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Link issues

fixes #1366

Summary By Copilot

  • Move BootstrapBlazor.MediaMtx from src/extensions to src/components and update the solution project reference.
  • Refactor runtime camera management APIs and gateway/service implementation while preserving the existing package name and public registration entry point.
  • Update package metadata, README, and bundled bb-mediamtx skill content.

Regression?

  • Yes
  • No

This change is intended to reorganize the component package and refactor its implementation without changing the package name or registration entry point. Upgrade impact was not verified by a build or test run.

Risk

  • High
  • Medium
  • Low

The package is moved to a new source location and its runtime gateway/service files are refactored, so project references, packaging, and runtime behavior require review.

Verification

  • Manual (required)
  • Automated

No build or test was run. Read-only verification confirmed the working tree was clean, local and origin/chore-mediamtx HEAD were 9f2356de1e1484d61f147a8100b021814def58cf, and the branch contains master.

Packaging changes reviewed?

  • Yes
  • No
  • N/A

Reviewed the solution reference, project move, package project file changes, README, and bundled skill packaging location.

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

The README and bundled skill are updated; no demo was added. The branch is based on the latest master and does not require merging additional commit content.

Summary by Sourcery

Move MediaMTX into the components package and make gateway and camera management available through an explicit on-demand service.

New Features:

  • Add an on-demand service API for starting the MediaMTX gateway and registering, updating, and removing camera paths, with per-camera RTSP sources and playback URLs.
  • Provide a specific exception when the MediaMTX executable is missing.

Enhancements:

  • Move the MediaMTX package from the extensions directory to components while preserving its package name and registration method.
  • Replace automatic hosted-service startup with explicit, retryable gateway startup; reuse the service's running process and avoid taking over other MediaMTX instances.
  • Clarify camera URL validation, credential handling, gateway lifecycle, and asynchronous service disposal.

Build:

  • Update the solution project reference and package project metadata for the new component location.

Documentation:

  • Add and update the MediaMTX README and bundled bb-mediamtx skill with service usage, configuration, security, playback, and tool deployment guidance.

@bb-auto bb-auto Bot added the enhancement New feature or request label Dec 2, 2026
@bb-auto bb-auto Bot added this to the v11.0.0 milestone Dec 2, 2026

@bb-auto bb-auto Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto approved by bb-auto

@sourcery-ai

sourcery-ai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Define the public camera and gateway option structures used by the service and its callers.

  • src/components/BootstrapBlazor.MediaMtx/MediaMtxCameraOptions.cs L1-49

API

Specify the service operations and process-launcher contract that callers and the default implementation rely on.

  • src/components/BootstrapBlazor.MediaMtx/IMediaMtxService.cs L1-55

Implementation

Implement on-demand gateway startup, readiness checks, process cleanup, and dynamic camera registration and removal.

  • src/components/BootstrapBlazor.MediaMtx/MediaMtxToolNotFoundException.cs L1-25

Retain the existing process-launcher and HTTP-client helper implementations at their new package location.

  • src/components/BootstrapBlazor.MediaMtx/HttpClientExtensions.cs
  • src/components/BootstrapBlazor.MediaMtx/MediaMtxProcessLauncher.cs

Configuration

Move the package into the components project tree and register the service without starting a hosted gateway automatically.

  • BootstrapBlazor.Extensions.slnx L46, L82 (removed lines)
  • src/extensions/BootstrapBlazor.MediaMtx/BootstrapBlazor.MediaMtx.csproj L4, L15-19

Documentation

Update the package README and bundled skill to explain the new on-demand service lifecycle and camera-management API.

  • src/components/BootstrapBlazor.MediaMtx/README.MediaMtx.md L1-277
  • src/components/BootstrapBlazor.MediaMtx/skills/bb-mediamtx/SKILL.md L1-74
  • src/extensions/BootstrapBlazor.MediaMtx/README.MediaMtx.md (deleted)
  • src/extensions/BootstrapBlazor.MediaMtx/skills/bb-mediamtx/SKILL.md (deleted)

Other changes

Files not grouped.

  • src/extensions/BootstrapBlazor.MediaMtx/IMediaMtxProcessLauncher.cs L25-26
  • src/extensions/BootstrapBlazor.MediaMtx/MediaMtxOptions.cs L11-12, L25-26, L32-33
  • src/extensions/BootstrapBlazor.MediaMtx/MediaMtxHostedService.cs L25-56 (+11 small edits)
  • src/extensions/BootstrapBlazor.MediaMtx/MediaMtxService.cs L25-29, L42-56, L172-191 (+7 small edits)
  • src/extensions/BootstrapBlazor.MediaMtx/MediaMtxServiceCollectionExtensions.cs L19-20, L30-40
  • src/extensions/BootstrapBlazor.MediaMtx/IMediaMtxService.cs (deleted)
  • src/extensions/BootstrapBlazor.MediaMtx/MediaMtxCameraOptions.cs (deleted)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@ArgoZhang
ArgoZhang merged commit a05389a into master Dec 2, 2026
3 checks passed
@ArgoZhang
ArgoZhang deleted the chore-mediamtx branch December 2, 2026 01:27
@sourcery-ai

sourcery-ai Bot commented Dec 2, 2026

Copy link
Copy Markdown

Linked issues

Checked at commit 9f2356d

#1366 feat(MediaMtx): add runtime RTSP camera management · 5 of 6 met

# Requirement Status Notes
1 Add a BootstrapBlazor.MediaMtx ASP.NET Core package that hosts a MediaMTX process. ✅ Met The package provides an on-demand gateway service that starts and manages the MediaMTX process.
2 Expose a server-side IRtspService for adding, updating, and removing camera paths. 🟡 Partly met The requested operations are available through IMediaMtxService, but no IRtspService is exposed.
3 Validate RTSP/RTSPS source addresses, support per-camera credentials, and return local WebRTC player URLs. ✅ Met The service validates absolute RTSP/RTSPS URLs without embedded user information, applies separately supplied credentials, and returns a playback URL.
4 Do not bundle the MediaMTX executable; allow configuring its path and gateway ports. ✅ Met The package project does not include the executable, and MediaMtxOptions exposes the executable path and gateway ports.
5 Keep the Control API bound to loopback with generated credentials. ✅ Met The gateway configuration binds the API to 127.0.0.1, and startup generates a random API password.
6 Document deployment, lifecycle, caller authorization, and RTSP destination access-policy responsibilities. ✅ Met The README covers tool deployment and process lifecycle, and calls out caller authorization and RTSP destination restrictions.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 4 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/components/BootstrapBlazor.MediaMtx/MediaMtxCameraOptions.cs" line_range="34" />
<code_context>
+    /// <para lang="en">Gets or sets the absolute RTSP or RTSPS URL with a host and without user information. Specify the port and stream path explicitly, and do not put credentials in the query string. For example: rtsp://192.168.1.100:554/Streaming/Channels/101</para>
+    /// <para><version>11.0.0</version></para>
+    /// </summary>
+    public string? RtspUrl { get; set; }
+
+    /// <summary>
</code_context>
<issue_to_address>
**Existing camera integrations break**

When an upgraded host retains `Url` in static camera configuration, an existing caller uses the former service contract, or a user follows the bundled HikVision skill, `MediaMtxCameraOptions` exposes `RtspUrl` instead of `Url`, so the skill no longer compiles and retained configuration leaves `RtspUrl` null; `BuildRtspSourceUrl` rejects that source, preventing registration. The changed `IMediaMtxService` return types also break existing callers and implementations at compile time and break already-built callers at runtime.

Restore a compatibility path for `Url` and the former service signatures, exposing the new behavior through additive APIs.

Also at `src/components/BootstrapBlazor.MediaMtx/IMediaMtxService.cs:34`, `src/components/BootstrapBlazor.MediaMtx/IMediaMtxService.cs:44`, `src/components/BootstrapBlazor.MediaMtx/IMediaMtxService.cs:54`.
</issue_to_address>

### Comment 2
<location path="src/components/BootstrapBlazor.MediaMtx/README.MediaMtx.md" line_range="82" />
<code_context>
+
+在已授权的 Interactive Server 页面使用播放器(引用 `BootstrapBlazor.HikVision`,它会依赖本包):
+
+```razor
+<HikVisionWebRtc Options="@camera" />
+
</code_context>
<issue_to_address>
**Documented player example fails**

When a consumer follows the README's HikVision player example, `HikVisionWebRtc` has no `Options` parameter and accepts `WebRtcUrl` instead, so the sample fails Razor compilation; the component also does not perform the described service startup or camera registration.

Update the example to use `WebRtcUrl` and revise the surrounding description to match the component's behavior.

Also at `src/components/BootstrapBlazor.MediaMtx/README.MediaMtx.md:83-95`, `src/components/BootstrapBlazor.MediaMtx/skills/bb-mediamtx/SKILL.md:36`.
</issue_to_address>

### Comment 3
<location path="src/components/BootstrapBlazor.MediaMtx/IMediaMtxService.cs" line_range="15" />
<code_context>
+/// <para lang="en">The default implementation throws <see cref="InvalidOperationException"/> for valid camera registration and deletion requests when the gateway is not running.</para>
+/// <para><version>11.0.0</version></para>
+/// </summary>
+public interface IMediaMtxService
+{
+    /// <summary>
</code_context>
<issue_to_address>
**Requested service interface**

The issue asks for an `IRtspService` exposing camera-path operations. The change provides those operations on `IMediaMtxService` instead, so consumers looking for the requested interface cannot use that API as specified.
</issue_to_address>

### Comment 4
<location path="src/components/BootstrapBlazor.MediaMtx/IMediaMtxService.cs" line_range="21" />
<code_context>
+    /// <para lang="zh">使用服务提供的配置启动 MediaMTX 进程。默认服务负责就绪探测和清理返回的进程。</para>
+    /// <para lang="en">Starts the MediaMTX process using the service-provided configuration. The default service probes readiness and cleans up the returned process.</para>
     /// <para><version>11.0.0</version></para>
     /// </summary>
     /// <param name="startInfo"><para lang="zh">进程启动配置。</para><para lang="en">The process start configuration.</para></param>
</code_context>
<issue_to_address>
**Startup API shows the wrong release version**

The new `EnsureStartedAsync` API is marked as introduced in 11.0.0 even though the package project version is 11.0.1. Generated API documentation therefore reports it as available in the wrong release.

Mark `EnsureStartedAsync` with version 11.0.1.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

/// <para lang="en">Gets or sets the absolute RTSP or RTSPS URL with a host and without user information. Specify the port and stream path explicitly, and do not put credentials in the query string. For example: rtsp://192.168.1.100:554/Streaming/Channels/101</para>
/// <para><version>11.0.0</version></para>
/// </summary>
public string? RtspUrl { get; set; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High · Existing camera integrations break

When an upgraded host retains Url in static camera configuration, an existing caller uses the former service contract, or a user follows the bundled HikVision skill, MediaMtxCameraOptions exposes RtspUrl instead of Url, so the skill no longer compiles and retained configuration leaves RtspUrl null; BuildRtspSourceUrl rejects that source, preventing registration. The changed IMediaMtxService return types also break existing callers and implementations at compile time and break already-built callers at runtime.

Restore a compatibility path for Url and the former service signatures, exposing the new behavior through additive APIs.

Also at src/components/BootstrapBlazor.MediaMtx/IMediaMtxService.cs:34, src/components/BootstrapBlazor.MediaMtx/IMediaMtxService.cs:44, src/components/BootstrapBlazor.MediaMtx/IMediaMtxService.cs:54.

Prompt for AI agents
In `src/components/BootstrapBlazor.MediaMtx/MediaMtxCameraOptions.cs` at line 34:

**Existing camera integrations break**

When an upgraded host retains `Url` in static camera configuration, an existing caller uses the former service contract, or a user follows the bundled HikVision skill, `MediaMtxCameraOptions` exposes `RtspUrl` instead of `Url`, so the skill no longer compiles and retained configuration leaves `RtspUrl` null; `BuildRtspSourceUrl` rejects that source, preventing registration. The changed `IMediaMtxService` return types also break existing callers and implementations at compile time and break already-built callers at runtime.

Restore a compatibility path for `Url` and the former service signatures, exposing the new behavior through additive APIs.

Also at `src/components/BootstrapBlazor.MediaMtx/IMediaMtxService.cs:34`, `src/components/BootstrapBlazor.MediaMtx/IMediaMtxService.cs:44`, `src/components/BootstrapBlazor.MediaMtx/IMediaMtxService.cs:54`.

From AGENTS.md L18:

保留已有公开签名和接口约定。


在已授权的 Interactive Server 页面使用播放器(引用 `BootstrapBlazor.HikVision`,它会依赖本包):

```razor

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High · Documented player example fails

When a consumer follows the README's HikVision player example, HikVisionWebRtc has no Options parameter and accepts WebRtcUrl instead, so the sample fails Razor compilation; the component also does not perform the described service startup or camera registration.

Update the example to use WebRtcUrl and revise the surrounding description to match the component's behavior.

Also at src/components/BootstrapBlazor.MediaMtx/README.MediaMtx.md:83-95, src/components/BootstrapBlazor.MediaMtx/skills/bb-mediamtx/SKILL.md:36.

Prompt for AI agents
In `src/components/BootstrapBlazor.MediaMtx/README.MediaMtx.md` at line 82:

**Documented player example fails**

When a consumer follows the README's HikVision player example, `HikVisionWebRtc` has no `Options` parameter and accepts `WebRtcUrl` instead, so the sample fails Razor compilation; the component also does not perform the described service startup or camera registration.

Update the example to use `WebRtcUrl` and revise the surrounding description to match the component's behavior.

Also at `src/components/BootstrapBlazor.MediaMtx/README.MediaMtx.md:83-95`, `src/components/BootstrapBlazor.MediaMtx/skills/bb-mediamtx/SKILL.md:36`.

/// <para lang="en">The default implementation throws <see cref="InvalidOperationException"/> for valid camera registration and deletion requests when the gateway is not running.</para>
/// <para><version>11.0.0</version></para>
/// </summary>
public interface IMediaMtxService

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Requested service interface

The issue asks for an IRtspService exposing camera-path operations. The change provides those operations on IMediaMtxService instead, so consumers looking for the requested interface cannot use that API as specified.

Prompt for AI agents
In `src/components/BootstrapBlazor.MediaMtx/IMediaMtxService.cs` at line 15:

**Requested service interface**

The issue asks for an `IRtspService` exposing camera-path operations. The change provides those operations on `IMediaMtxService` instead, so consumers looking for the requested interface cannot use that API as specified.

From #1366:

Expose a server-side IRtspService for adding, updating, and removing camera paths.

/// <para lang="zh">确保网关已启动并就绪,失败时抛出异常。默认实现复用本宿主的运行中进程;工具缺失时需手动部署。</para>
/// <para lang="en">Ensures the gateway is running and ready, throwing an exception on failure. The default service reuses its running process; missing tools must be deployed manually.</para>
/// <para><version>11.0.0</version></para>
/// </summary>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚪ Low · Startup API shows the wrong release version

The new EnsureStartedAsync API is marked as introduced in 11.0.0 even though the package project version is 11.0.1. Generated API documentation therefore reports it as available in the wrong release.

Mark EnsureStartedAsync with version 11.0.1.

Prompt for AI agents
In `src/components/BootstrapBlazor.MediaMtx/IMediaMtxService.cs` at line 21:

**Startup API shows the wrong release version**

The new `EnsureStartedAsync` API is marked as introduced in 11.0.0 even though the package project version is 11.0.1. Generated API documentation therefore reports it as available in the wrong release.

Mark `EnsureStartedAsync` with version 11.0.1.

From docs/agents/component-checklist.md L6:

- XML 注释遵循 [BB 组件规范](https://github.com/dotnetcore/BootstrapBlazor/blob/main/docs/agents/component-checklist.md#参数与-api)。新增 API 时标记其所属扩展包计划发布的正式版本;修改已有 API 时保留其引入版本。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(MediaMtx): add runtime RTSP camera management

1 participant